import { Component, OnInit } from '@angular/core';

import {RECOMENDITEMS} from '../const/api'
import {HttpService} from '../utils/http.service';


@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
    styleUrls:['../../assets/css/item_cat.css']
})
export class IndexComponent implements OnInit {
    slides: Array<any> = [];
  //保存的推荐商品的对象数组
  recommendedItems:Array<any>=[];
  constructor(private HttpService : HttpService) { }

  ngOnInit() {
    this.loadData()
  }
  loadData(){
    this.HttpService.sendRequest(RECOMENDITEMS).subscribe(res=>{
      //对slides数组进行赋值
      if(res.carouselItems){
        console.log(res.carouselItems);
        for(var i=0;i<res.carouselItems.length;i++)
        {
          this.slides.push({
            image:res.carouselItems[i].img
          })
        }
      }
      //保存推荐商品的数据
      this.recommendedItems = res.recommendedItems;
      console.log(this.recommendedItems);
    })
  }
}
